package com.leesche.netdoll.communication;

import java.nio.ByteOrder;
import java.util.concurrent.TimeUnit;

import com.leesche.netdoll.communication.Settings.ServerConfig;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.timeout.IdleStateHandler;

public class ServerInitializer extends ChannelInitializer<SocketChannel> {

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {

		ChannelPipeline pipeline = ch.pipeline();

		pipeline.addLast(new IdleStateHandler(0, 0, ServerConfig.TIMEOUT, TimeUnit.MILLISECONDS));
		pipeline.addLast(new ByteBufferLogHandler());
		pipeline.addLast(new DoubleHeaderLengthFieldBaseFrameDecoder(ByteOrder.LITTLE_ENDIAN, 2*1024, 1, 2, -3, 0, true));
		pipeline.addLast(new ReceiveHandler());
	}

}
